VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "VBModule"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private mFileLoaded As Boolean
Private mFileSize As Long
Private mFile As String
Private mName As String
Private mMemberVarCount As Long
Private mGlobalVarCount As Long
Private mProcs As Collection
Private mLines() As VBLine
Private mLineCount As Long
Private mType As vbModuleType
Private mProcLineCount As Long

Public Enum vbModuleType
    vbmtmodule
    vbmtForm
    vbmtclass
End Enum

Public Function HasProcsMoreComplexThan(minComplexity As Double) As Boolean
    
Dim proc As VBProc

    For Each proc In mProcs
        If proc.Complexity > minComplexity Then
            HasProcsMoreComplexThan = True
            Exit Function
        End If
    Next
    
    HasProcsMoreComplexThan = False
    
End Function

Public Property Get Procedures() As Collection
    Set Procedures = mProcs
End Property

Public Sub LoadTextFrom(reader As IVBModuleReader)

Dim inProc As Boolean
Dim thisLine As VBLine

    Set thisLine = reader.NextVBLine
    
    mName = reader.Filename

    Do Until reader.AtEndOfStream Or thisLine.IsProcHeaderLine
    
        LookForMemberVars thisLine
        LookForGlobalVars thisLine
        
        Set thisLine = reader.NextVBLine
        
    Loop
        
    Do
        If thisLine.IsProcHeaderLine Then
            inProc = True
        End If
        
        If inProc Then
            AddLine thisLine
        End If
        
        If thisLine.IsProcEndLine Then
        
            AddAProc mLines
                   
            ClearLines
            
            inProc = False
            
        End If
        
        If reader.AtEndOfStream Then
            Exit Do
        End If
        
        Set thisLine = reader.NextVBLine
    Loop

    Set thisLine = Nothing

End Sub

Private Sub AddLine(lineToAdd As VBLine)

    mLineCount = mLineCount + 1
    mProcLineCount = mProcLineCount + 1
    ReDim Preserve mLines(mProcLineCount)
    Set mLines(mProcLineCount) = lineToAdd

End Sub

Private Sub ClearLines()

    Erase mLines
    mProcLineCount = -1
    
End Sub

Private Sub AddAProc(procLines() As VBLine)

Dim newProc As VBProc

    Set newProc = New VBProc
    
    newProc.ParentName = mName
    newProc.Load procLines
    
    mProcs.Add newProc

End Sub

Private Sub LookForMemberVars(theLine As VBLine)

    If theLine.IsADeclaration Then
        If mType = vbmtclass Then
            mMemberVarCount = mMemberVarCount + theLine.DeclaredVariableCount
        Else
            If Not theLine.TextWord(1) = "global" _
            And Not theLine.TextWord(1) = "public" Then
                mMemberVarCount = mMemberVarCount + theLine.DeclaredVariableCount
            End If
        End If
    End If

End Sub

Private Sub LookForGlobalVars(theLine As VBLine)

    If Not theLine.IsADeclaration Then
        Exit Sub
    End If
    
    Select Case mType
    Case vbmtmodule, vbmtForm
        If theLine.IsGlobal And theLine.IsADeclaration Then
            mGlobalVarCount = mGlobalVarCount + theLine.DeclaredVariableCount
        End If
    End Select
    
End Sub

Public Property Get proc(whichProc As Long) As VBProc
    Set proc = mProcs(whichProc)
End Property

Public Property Get FileLoaded() As Boolean
    FileLoaded = mFileLoaded
End Property

Public Property Get FileSize() As Long
    FileSize = mFileSize
End Property

Public Property Get Name() As String
    Name = mName
End Property

Public Property Get ProcCount() As Long
    ProcCount = mProcs.Count
End Property

Public Property Get MemberVarCount() As Long
    MemberVarCount = mMemberVarCount
End Property

Public Property Get GlobalVarCount() As Long
    GlobalVarCount = mGlobalVarCount
End Property

Public Property Get ModuleType() As vbModuleType
    ModuleType = mType
End Property

Public Property Get ModuleTypeString() As String

    Select Case mType
    Case vbmtclass
        ModuleTypeString = "Class"
    Case vbmtForm
        ModuleTypeString = "Form"
    Case vbmtmodule
        ModuleTypeString = "Module"
    End Select
    
End Property

Public Property Get LineCount() As Long
    LineCount = mLineCount
End Property

Private Sub Class_Initialize()
    Set mProcs = New Collection
End Sub
